import Vue  from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
	 state:{
		loginStatus:false,
		token:'',
		userInfo:{}
	 },
	 mutations:{
	    login(state,token)
		{
			state.loginStatus = true;
			state.token = token
			uni.setStorageSync("token",token)
		},
		loginUser(state,userInfo)
		{
			state.userInfo  = userInfo;
			uni.setStorageSync("userInfo",JSON.stringify(userInfo))
		},
		initUser(state){
			let user = uni.getStorageSync("userInfo");
			if(user)
			{
				user =JSON.parse(user);
				state.loginStatus = true
			}	
		},
		logout(state)
		{
			state.loginStatus = false;
			state.userInfo = {},
			uni.removeStorageSync("userInfo")
		}
	 },
})
